package com.yanqu.road.server.channelserver.manager.log.impl;

import com.yanqu.road.entity.log.LogWasheOperate;
import com.yanqu.road.logic.bussiness.LogDaoHelper;
import com.yanqu.road.server.channelserver.manager.log.BaseChannelLog;

import java.util.ArrayList;
import java.util.List;

public class ChannelLogWasheLogic extends BaseChannelLog {

    private static final List<LogWasheOperate> logWasheOperateList = new ArrayList<>();

    public static void addLogWasheOperate(LogWasheOperate log) {
        if (log == null) {
            logger.error("addLogWasheOperate error ! log is null !");
            return;
        }
        synchronized (logWasheOperateList) {
            logWasheOperateList.add(log);
        }
    }

    private static void saveLogWasheOperate() {
        List<LogWasheOperate> list;
        synchronized (logWasheOperateList) {
            list = new ArrayList<>(logWasheOperateList);
            logWasheOperateList.clear();
        }
        if (list.size() > 0) {
            LogDaoHelper.getLogWasheOperateDaoImpl().addLogWasheOperateList(list);
        }
        if (list.size() >= 1000) {
            logger.debug("saveLogWasheOperate size {}", list.size());
        }
    }

    public void save() {
        saveLogWasheOperate();
    }

}
